package src.server;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author CsCN
 */
public class ScoreObj implements Comparable<ScoreObj>, Serializable {
    public int id;
    /**
     * 玩家名称
     */
    private String userName;
    /**
     * 分数
     */
    private int score;
    /**
     * Date库默认的字符串时间
     */
    private String time;

    public ScoreObj(int id, String userName, int score, String time) {
        this.id = id;
        this.userName = userName;
        this.score = score;
        this.time = time;
    }

    public ScoreObj(String userName, int score) {
        this.userName = userName;
        this.score = score;
        Date day=new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        time = df.format(day);
    }


    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    /**
     * 重写比较方法, 方便排序, 注意是倒序
     */
    @Override
    public int compareTo(ScoreObj o) {
        return -Integer.compare(score, o.score);
    }
}
